# FROM jenkins/ssh-agent:latest
# FROM ubuntu:22.04
FROM ubuntu:20.04
USER root
ENV TZ=Asia/Shanghai



LABEL MAINTAINER="GONSIN"
RUN DEBIAN_FRONTEND="noninteractive" apt-get -y install
ENV TZ=Asia/Shanghai
ENV LANG C.UTF-8

RUN apt-get update
RUN apt install gnupg -y
RUN apt install tzdata -y
RUN ln -snf /usr/share/zoneinfo/"${TZ}" /etc/localtime && echo "${TZ}" > /etc/timezone \
    && dpkg-reconfigure -f noninteractive tzdata


COPY sources.list /etc/apt/sources.list
# RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 3B4FE6ACC0B21F32 871920D1991BC93C
RUN apt-get update


# 安装 docker-compose 和 docker
RUN apt-get install -y wget
RUN wget -nc http://update.gonsincloud.com/jenkins/docker-compose
RUN mkdir /usr/local/docker
RUN mv docker-compose /usr/local/docker/docker-compose
ENV DOCKER_HOME /usr/local/docker
ENV PATH $PATH:$DOCKER_HOME
RUN apt-get install -y lsb-release
RUN apt install curl -y
# RUN curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc https://download.docker.com/linux/debian/gpg
# RUN echo "deb [arch=$(dpkg --print-architecture) \
#   signed-by=/usr/share/keyrings/docker-archive-keyring.asc] \
#   https://download.docker.com/linux/debian \
#   $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list
# RUN apt-get update
# RUN apt-get install -y ca-certificates curl gnupg
# RUN apt-get install -y docker-ce-cli
RUN install -m 0755 -d /etc/apt/keyrings
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
RUN  chmod a+r /etc/apt/keyrings/docker.gpg
RUN echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  tee /etc/apt/sources.list.d/docker.list > /dev/null
RUN apt-get update
RUN apt-get install -y docker-ce-cli


RUN apt-get install -y vim
RUN apt-get install -y zip
RUN apt-get install -y tar
RUN apt install openssh-server -y


# RUN mkdir /root/.ssh
# COPY ssh /root/.ssh
# RUN cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
# RUN chmod 777 /root/.ssh/authorized_keys
# RUN chmod 777 /root/.ssh

# RUN /etc/init.d/ssh restart

## 安装java 11
# RUN wget http://update.gonsincloud.com/jenkins/jdk-8u231-linux-x64.tar.gz
# RUN tar zxvf jdk-8u231-linux-x64.tar.gz -C /usr/local/
# ENV JAVA_HOME /usr/local/jdk1.8.0_231
RUN wget https://mirrors.tuna.tsinghua.edu.cn/Adoptium/11/jdk/x64/linux/OpenJDK11U-jdk_x64_linux_hotspot_11.0.22_7.tar.gz
RUN mkdir /root/jenkins -p
RUN tar zxvf OpenJDK11U-jdk_x64_linux_hotspot_11.0.22_7.tar.gz -C /root/jenkins
RUN mv /root/jenkins/jdk-11.0.22+7 /root/jenkins/jdk -f
ENV JAVA_HOME /root/jenkins/jdk
ENV PATH $PATH:$JAVA_HOME/bin

## 安装java 8
# RUN wget http://update.gonsincloud.com/jenkins/jdk-8u231-linux-x64.tar.gz
# RUN tar zxvf jdk-8u231-linux-x64.tar.gz -C /usr/local/
# ENV JAVA_HOME /usr/local/jdk1.8.0_231
# ENV PATH $PATH:$JAVA_HOME/bin
# RUN java -version

# 安装node npm
RUN wget http://update.gonsincloud.com/jenkins/node-v16.16.0-linux-x64.tar
RUN tar -xvf node-v16.16.0-linux-x64.tar -C /usr/local/
ENV NPM_HOME /usr/local/node-v16.16.0-linux-x64
ENV PATH $PATH:$NPM_HOME/bin
RUN npm -version

# 安装maven
RUN wget -nc http://update.gonsincloud.com/jenkins/apache-maven-3.6.2-bin.tar.gz
RUN tar zxvf apache-maven-3.6.2-bin.tar.gz -C /usr/local/
RUN cp /usr/local/apache-maven-3.6.2/conf/settings.xml /usr/local/apache-maven-3.6.2/conf/settings.xml.bk
COPY settings.xml /usr/local/apache-maven-3.6.2/conf/settings.xml
ENV MAVEN_HOME /usr/local/apache-maven-3.6.2
ENV PATH $PATH:$MAVEN_HOME/bin
RUN mvn -version

# 安装gradle
# RUN wget -nc http://update.gonsincloud.com/jenkins/gradle-6.7.1-bin.zip
ENV GRADLE_VERSION=7.6.3
RUN wget -nc http://update.gonsincloud.com/jenkins/gradle-${GRADLE_VERSION}-bin.zip
RUN mkdir -p /usr/local/android/wrapper/dists/gradle-${GRADLE_VERSION}-bin/bwlcbys1h7rz3272sye1xwiv6
RUN cp gradle-${GRADLE_VERSION}-bin.zip /usr/local/android/wrapper/dists/gradle-${GRADLE_VERSION}-bin/bwlcbys1h7rz3272sye1xwiv6/
RUN unzip -d /usr/local/ gradle-${GRADLE_VERSION}-bin.zip
RUN chmod 777 /usr/local/gradle-${GRADLE_VERSION}/bin
ENV GRADLE_HOME /usr/local/gradle-${GRADLE_VERSION}
ENV PATH $PATH:$GRADLE_HOME/bin
ENV GRADLE_USER_HOME /usr/local/android
COPY init.gradle /usr/local/android/init.gradle
RUN gradle -version



# 安装安卓SDK
RUN wget -nc http://update.gonsincloud.com/jenkins/commandlinetools-linux-8512546_latest.zip
RUN unzip -d /usr/local/android/sdk/ commandlinetools-linux-8512546_latest.zip
RUN mkdir /usr/local/android/sdk/cmdline-tools/latest
RUN mv /usr/local/android/sdk/cmdline-tools/bin  /usr/local/android/sdk/cmdline-tools/latest/bin
RUN mv /usr/local/android/sdk/cmdline-tools/lib  /usr/local/android/sdk/cmdline-tools/latest/lib
RUN mv /usr/local/android/sdk/cmdline-tools/NOTICE.txt  /usr/local/android/sdk/cmdline-tools/latest/NOTICE.txt
RUN mv /usr/local/android/sdk/cmdline-tools/source.properties  /usr/local/android/sdk/cmdline-tools/latest/source.properties


ENV ANDROID_HOME /usr/local/android/sdk/
ENV PATH $PATH:$ANDROID_HOME/cmdline-tools/latest/bin
RUN sdkmanager --list
RUN sdkmanager --install "platform-tools"
RUN sdkmanager --install "build-tools;28.0.3"
RUN sdkmanager --install "emulator"
RUN sdkmanager --install "tools"
RUN sdkmanager --install "platforms;android-28"
RUN yes | sdkmanager --licenses



#安装apifox
RUN npm config set registry http://registry.npm.taobao.org
RUN npm install -g apifox-cli


# 安装jmeter
RUN wget -nc http://update.gonsincloud.com/jenkins/apache-jmeter-5.3.tgz
RUN tar zxvf apache-jmeter-5.3.tgz -C /usr/local/
ENV JMETER_HOME /usr/local/apache-jmeter-5.3
ENV PATH $PATH:$JMETER_HOME/bin
RUN jmeter -v


# 安装python
RUN apt install -y python3
RUN python3 --version


## 安装qt

## 待补充
## 安装ffmpeg

# 安装nvm
RUN apt install git -y
RUN curl -o- http://update.gonsincloud.com/jenkins/install_nvm.sh | bash

# 秘钥
ENV JENKINS_AGENT_SSH_PUBKEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDWqy37TjwbA4C6rDMdNK3xGufkK4HLdma5xQfYZIteWL4rEs/HAAQxqGHTwjH3peIEQmrRj/a38xIdDiitFlhZ9W+DtgfJdzh9pfDvxlUhONImbpFmNdtGpSI7vhshxF4IscPoQhroBSBj4Hx/z1b6UTeTUlpfhSVdAc/FBfk+PBtX0Ij9gi7whseCbnmWUKrZSL7AH1aIoixcdiwfiGmkl9JurAxZ1gNtkXVO0MOcBCo0lBE2iy8aHCjf+hTry2d+HNKrXaRf7lsdS0MH0lhGjidEBGcKmtXsCgR81JvtrXCl9zjwp/EoV4FqovtBamJqFlYTS7PXmi+SmMz1Uk4/ dan@localhost.localdomain"
ENV JENKINS_AGENT_HOME /root

COPY sshd_config /etc/ssh/sshd_config
COPY setup-sshd /usr/sbin/setup-sshd
COPY bash_profile /root/.bash_profile
COPY profile /etc/profile
COPY bash.bashrc /etc/bash.bashrc
RUN mkdir /root/.ssh
COPY ssh /root/.ssh
RUN cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
RUN chmod 777 /root/.ssh/authorized_keys
RUN chmod 777 /root/.ssh
RUN /etc/init.d/ssh restart
RUN ssh-keygen -A
RUN echo root:123|chpasswd
# RUN chown root:root /run
# RUN mkdir /run/sshd
CMD [ "/usr/sbin/setup-sshd"]
COPY init.gradle /root/.gradle/init.gradle

RUN ln -s ${GRADLE_HOME}/bin/gradle /usr/local/bin/gradle
RUN ln -s ${NPM_HOME}/bin/npm /usr/local/bin/npm
RUN ln -s ${NPM_HOME}/bin/node /usr/local/bin/node
RUN ln -s ${MAVEN_HOME}/bin/mvn /usr/local/bin/mvn
RUN ln -s ${JMETER_HOME}/bin/jmeter /usr/local/bin/jmeter
RUN ln -s ${ANDROID_HOME}cmdline-tools/latest/bin/sdkmanager /usr/local/bin/sdkmanager
RUN ln -s ${JAVA_HOME}/bin/java /usr/local/bin/java
RUN chmod 777 /usr/local/docker/docker-compose
RUN ln -s ${DOCKER_HOME}/docker-compose /usr/local/bin/docker-compose
WORKDIR /root


